//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing.Diagram
{
    class Choose: IOfficeXmlSerializable
    {
        readonly List<When> ifs = new List<When>();
        private Otherwise _else;
        private string name = string.Empty;

        public void ReadXml(ReadContext context)
        {
            using (var c = context.Read("choose"))
            {
                this.name = c.GetOptionalString("name", string.Empty);
                ifs.Clear();
                ifs.AddRange(c.ReadOptionalWhile<When>("if"));
                _else = c.ReadOptionalElement<Otherwise>(Otherwise.xmlName );
            }

        }

        public void WriteXml(WriteContext context)
        {
            using (var c = context.Write("choose"))
            {
                c.SetOptionalString("name", name, string.Empty);
                c.WriteElements(ifs);
                c.WriteElement(_else);
            }
        }
    }
}